//
//  LocalSchoolsService.m
//  HZHome
//
//  Created by SunShine on 13-10-13.
//  Copyright (c) 2013年 xzysun. All rights reserved.
//

#import "LocalSchoolsService.h"

@interface LocalSchoolsService()
@property (assign, nonatomic) SelectedSchoolType currentSelectedSchool;
@end

@implementation LocalSchoolsService

-(id)init
{
    self = [super init];
    if (self) {
        _dataItemName = @"CommonMineQueryItem";
        self.currentSelectedSchool = SelectedHighSchool;
    }
    return self;
}

-(NSArray *)getSegmentsTitles
{
    NSArray *titles = [NSArray arrayWithObjects:@"中学", @"小学", @"幼儿园", nil];
    return titles;
}

-(void)selectSegmentBarAtIndex:(NSInteger)selected
{
    [self cancelAllRequest];
    switch (selected) {
        case 0:
            self.currentSelectedSchool = SelectedHighSchool;
            break;
        case 1:
            self.currentSelectedSchool = SelectedPrimarySchool;
            break;
        case 2:
            self.currentSelectedSchool = SelectedKindergarten;
            break;
        default:
            break;
    }
    [self loadDataWithKey:nil];
}

-(void)loadDataWithKey:(NSString *)keyOrNil
{
    _currentPageNo = 1;//刷新或查询的时候将请求页码变为1
    if (self.dataList) {
        self.dataList = nil;
    }
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setValue:[NSString stringWithFormat:@"%d",self.currentSelectedSchool] forKey:@"categoryid"];
    if (keyOrNil) {
        [params setValue:keyOrNil forKey:@"title"];
    } else {
        [params setValue:@"" forKey:@"title"];
    }
    [self doHttpPost:WOYAOCHA headers:nil path:[NSString stringWithFormat:@"/%d",_currentPageNo] parameters:params];
}

-(void)loadMoreDataWithKey:(NSString *)keyOrNil
{
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setValue:[NSString stringWithFormat:@"%d",self.currentSelectedSchool] forKey:@"categoryid"];
    if (keyOrNil) {
        [params setValue:keyOrNil forKey:@"title"];
    } else {
        [params setValue:@"" forKey:@"title"];
    }
    [self doHttpPost:WOYAOCHA headers:nil path:[NSString stringWithFormat:@"/%d",_currentPageNo+1] parameters:params];
}

-(CGFloat)heightForCellAtRow:(NSIndexPath *)index
{
    return 64.0f;
}

-(void)configCell:(UITableViewCell *)cell atIndex:(NSIndexPath *)index
{
    CommonMineQueryItem *item = [self.dataList objectAtIndex:index.row];
    InfoWithPhoneAndMapCell *tempCell = (InfoWithPhoneAndMapCell*)cell;
    [self configInfoWithPhoneAndMapCell:tempCell withItem:item atIndex:index.row];
}
@end
